// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import router from './router'
import 'common/stylus/index.styl'
import store from './store/index.js'
// import store from './store' // store对象
import axios from 'axios'

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import './common/stylus/element-ui/theme-default/index.css'
import tableUtils from './common/js/table_utils' // 表头工具方法
import groupUtils from './common/js/group_utils' // 分组工具方法
import cellUtils from './common/js/cell_utils' // 分组工具方法
import utils from './common/js/utils' // 工具方法

import uploader from 'vue-simple-uploader' // 分片上传工具
import onlyNumber from './directive/el-input' // element-input对金额输入框格式化指令
import componentSelf from './common/components/index' // 全局自定义组件引入
import md5 from '../static/MD5'

console.log(md5('1', '222').toUpperCase())

// import axios from 'axios'
// Vue.prototype.$http = axios

Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.use(tableUtils)
Vue.use(groupUtils)
Vue.use(cellUtils)
Vue.use(utils)
Vue.use(uploader)

Vue.use(onlyNumber) // element-input对金额输入框格式化指令
Vue.use(componentSelf) // element-input对金额输入框
// todo
// {authorization: "d3e44f52-cccc-4ee8-a949-df3a8dd43348", key: "krixh27rnfis9567wnr83n48sasfses"}
axios.interceptors.request.use(
    config => {
        config.headers.Authorization = store.state.tokens
        config.headers.companyCode = store.state.loginParams.companyCode
        config.headers.timestamp = store.state.loginParams.timestamp
        config.headers.signature = store.state.loginParams.signature
        config.headers.loginType = '1'
        return config
    },
    err => {
        return Promise.reject(err)
    })
axios.interceptors.response.use(
    response => {
        if (response.headers.authorization) {
            // sessionStorage.setItem('authorization', response.headers.authorization)
        }
        if (response.data.ret !== '0' && response.data.ret !== 0) {
            store.commit('setMsg', response.data.msg)
        }
        console.log(response)
        return response
    },
    error => {
        return Promise.reject(error)
    })
Vue.prototype.$axios = axios

/* eslint-disable no-new */
new Vue({
    el: '#app',
    router,
    store,
    template: '<App/>',
    components: {
        App
    }
})
